package com.sfh.dog.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

/**
 * 
 * @author sWX229906
 *
 * @param <T> 数据
 * @param <V> 视图
 */
public abstract class LBaseAdapter<T, V> extends BaseAdapter
{
   public LayoutInflater mInflater;
    
   public int mLayout;
    
   public  List<T> mList;
   public Context mContext; 
    public LBaseAdapter(Context context, int layout, List<T> list)
    {
        this.mContext = context;
        this.mInflater = LayoutInflater.from(context);
        this.mLayout = layout;
        this.mList = list;
    }
//    
//    public LBaseAdapter(Context context, int layout)
//    {
//        this.mContext = context;
//        this.mInflater = LayoutInflater.from(context);
//        this.mLayout = layout;
//    }
//    
//    public LBaseAdapter(Context context, List<T> list)
//    {
//        this.mContext = context;
//        this.mInflater = LayoutInflater.from(context);
//        this.mList = list;
//    }
    
    
    @Override
    public int getCount()
    {
        return mList.size();
    }
    
    @Override
    public Object getItem(int arg0)
    {
        return mList.get(arg0);
    }
    
    @Override
    public long getItemId(int arg0)
    {
        return arg0;
    }
    
    @Override
    public View getView(int position, View view, ViewGroup parent)
    {
        V mHondler = null;
        if (view == null)
        {
            view = mInflater.inflate(mLayout, parent, false);
            mHondler = findHondView(view);
            view.setTag(mHondler);
        }
        else
        {
            mHondler = (V)view.getTag();
        }
        Object object = getItem(position);
        setViewData((T)object, mHondler,position);
        return view;
    }
    
    /**
     * 查找资源控件
     * @param view
     * @return
     */
    public abstract V findHondView(View view);
    
    /**
     * 资源控件设置数据
     * @param t
     * @param hondler
     */
    public abstract void setViewData(T t, V hondler, int position);
    
}
